from qcloud_cos import CosConfig, CosS3Client


def crate_bucket(bucket,region=''):
    """
    创建桶
    :param bucket:桶名称
    :param region:区域
    :return:
    """
    secret_id = ''
    secret_key = ''

    region = ''

    config = CosConfig(Region=region,SecretId=secret_id,SecretKey=secret_key)

    client = CosS3Client(config)

    client.create_bucket(Bucket=bucket
                         ,ACL='public-read')


def upload_file(bucket,region,file_object,key):
    secret_id = ''
    secret_key = ''
    region = ''
    config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key)
    client = CosS3Client(config)

    response = client.upload_file_from_buffer(
        Bucket=bucket,
        Body=file_object, #文件对象
        Key=key     # 上传到桶之后的文件名
    )
    return 'https://{}.cos{}.myqcloud.com/{}'.format(bucket,region, key)
